package core.proto.vis.action;

import java.util.Iterator;
import java.util.Map;

import prefuse.Visualization;
import prefuse.action.GroupAction;
import prefuse.data.Node;
import prefuse.data.tuple.TupleSet;
import prefuse.visual.NodeItem;
import core.proto.vis.action.util.Position;

public class SetLockNodeAction extends GroupAction
{
    private Map<NodeItem, Position> nodePositionLock;

    public void run( double frac ) {
        TupleSet nodes = m_vis.getGroup( Visualization.FOCUS_ITEMS );
        if( nodes == null || nodes.getTupleCount() == 0 )
            return;

        Object o = null;
        @SuppressWarnings("rawtypes")
        Iterator tuples = nodes.tuples();
        while( tuples.hasNext() ) {
            o = tuples.next();
            if( !(o instanceof NodeItem) ) {
                continue;
            }
            NodeItem node = (NodeItem) o;
            double x = node.getX();
            double y = node.getY();
            nodePositionLock.put( node, new Position( x, y ) );
        }
    }

    public SetLockNodeAction( Map<NodeItem, Position> nodePosition ) {
        this.nodePositionLock = nodePosition;
    }
}